package com.xyoto.community.config;

import com.xyoto.community.pojo.Type2TopicUserHotTableInfo;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.HashMap;
import java.util.Map;

/**
 * 话题下的用户活跃表配置
 */
@PropertySource(value = "classpath:topic_user_hot.properties",encoding = "utf-8")
@ConfigurationProperties(prefix = "topic-user-hot-map")
@Configuration
@Getter
@Setter
public class TopicUserHotTableConfig {

    /**
     * 维护话题id到数据库表名关系
     */
    private Map<Integer, String> topicId2TopicUserHotTableNameMap = new HashMap<>();

    /**
     * 维护操作类型到该类型增加的活跃度数关系
     */
    private Map<Integer, Double> operateType2ScoreMap = new HashMap<>();

    /**
     * 根据话题id获取到该话题对应的用户活跃度表信息
     * @param topicId 话题id
     * @return 用户活跃度表信息
     */
    public Type2TopicUserHotTableInfo getTopicUserHotInfoByTopicId(Integer topicId){
        String tableName = topicId2TopicUserHotTableNameMap.get(topicId);
        if (!StringUtils.isEmpty(tableName)){
            return new Type2TopicUserHotTableInfo(tableName);
        }
        return null;
    }

    /**
     * 根据操作类型获取该操作对应增加的活跃度数
     * @param operateType 操作类型
     * @return 增加的活跃度数
     */
    public Double getScoreByOperateType(Integer operateType){
        return operateType2ScoreMap.get(operateType);
    }

}



